cmake_minimum_required(VERSION 3.8...3.15 FATAL_ERROR)

# c++11标准
set(CXX_STANDARD C11)

# 项目名称
project(app)

#------- moose和libmesh配置 --------#
# 设置moose路径
#set(MOOSE_CC_DIR "./moose"  CACHE PATH "moose路径")
# 如果moose文件不存在，报错
if(NOT EXISTS ${PROJECT_SOURCE_DIR}/moose)
	message(FATAL_ERROR "${PROJECT_SOURCE_DIR}/moose文件夹不存在")
endif()
set(MOOSE_CC_DIR ${PROJECT_SOURCE_DIR}/moose)


# 如果libmesh文件不存在，报错
if(NOT EXISTS ${MOOSE_CC_DIR}/libmesh)
	message(FATAL_ERROR "${MOOSE_CC_DIR}/libmesh文件夹不存在")
endif()
set(LIBMESH_CC_DIR ${MOOSE_CC_DIR}/libmesh)

# 配置libmesh
add_library(libmesh INTERFACE)
target_include_directories(libmesh INTERFACE ${LIBMESH_CC_DIR}/installed/include)
target_include_directories(libmesh INTERFACE ${MOOSE_CC_DIR}/petsc/include)
target_include_directories(libmesh INTERFACE ${LIBMESH_CC_DIR}/installed/include/mpich/include)

#file(GLOB_RECURSE  libmesh_source ${LIBMESH_CC_DIR}/*.cc)  
#message(STATUS ${libmesh_source})
#target_sources(libmesh INTERFACE ${libmesh_source})

#  如果framework文件不存在，报错
if(NOT EXISTS ${MOOSE_CC_DIR}/framework)
	message(FATAL_ERROR "${MOOSE_CC_DIR}/framework文件夹不存在")
endif()

# 配置moose
add_library(moose INTERFACE)
target_link_libraries(moose INTERFACE libmesh)

# 给moose加入头文件
file(GLOB moose_include LIST_DIRECTORIES  true ${MOOSE_CC_DIR}/framework/include/*)
foreach(file IN LISTS moose_include)
    target_include_directories(moose INTERFACE ${file})
endforeach(file)
target_include_directories(moose INTERFACE ${MOOSE_CC_DIR}/framework/contrib/boost/include)
target_include_directories(moose INTERFACE ${MOOSE_CC_DIR}/framework/contrib/hit)

#TODO: src/, test/, unit/ 
file(GLOB_RECURSE  _source ${PROJECT_SOURCE_DIR}/src/*.cpp)

# 配置app
add_library(app STATIC ${_source} )
#add_library(app INTERFACE)
file(GLOB app_include LIST_DIRECTORIES  true ${CMAKE_CURRENT_SOURCE_DIR}/include/*)
foreach(file IN LISTS app_include)
    target_include_directories(app PUBLIC ${file})
endforeach(file)

# 加入O4TestApp.h头文件依赖
target_include_directories(app PUBLIC  ${CMAKE_CURRENT_SOURCE_DIR}/test/include/base/)

# 链接moose
target_link_libraries(app PUBLIC moose)

